package com.example.wecompose.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import com.example.wecompose.WeViewModel
import com.example.wecompose.data.Chat
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable

@Serializable
object HomePage

@Composable
fun HomePage(viewModel: WeViewModel,onOpenChat:(Chat)-> Unit) {
    Column(
        Modifier.fillMaxSize()
    ) {
        val pagerState = rememberPagerState { 4 }
        HorizontalPager(
            pagerState, Modifier.weight(1f)

        ) { page ->
            when (page) {
                0 -> ChatList(viewModel.chats,onOpenChat,viewModel)
                1 -> ContactList(viewModel.contacts,viewModel)
                2 -> DiscoveryList(viewModel)
                3 -> MeList(viewModel)

            }
        }

        val scope = rememberCoroutineScope()
        WeNavigationBar(pagerState.currentPage) {
            scope.launch {
                pagerState.animateScrollToPage(it)
            }
        }
    }
}